<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .del{
      color: red;
      cursor: pointer;
    }
  </style>
</head>
<body>
  <input type="text" class="text">
  <button class="btn">添加</button>
  <ul class="list">
    <li>香蕉 <span class="del">删除</span></li>
    <li>苹果 <span class="del">删除</span></li>
    <li>鸭梨 <span class="del">删除</span></li>
  </ul>
  <script>
    var oText = document.querySelector(".text");
    var oBtn = document.querySelector(".btn");
    var oList = document.querySelector(".list");
    var aDel = document.querySelectorAll(".del");
    oBtn.onclick = function(){
      var val = oText.value+"&nbsp;";
      var oLi = document.createElement("li");
      oLi.innerHTML = val;
      var oSpan = document.createElement("span");
      oSpan.className = "del";
      oSpan.innerHTML = "删除";
      oLi.appendChild(oSpan);
      oList.appendChild(oLi);
    }
    for(var i=0;i<aDel.length;i++){
      aDel[i].onclick = function(){
        console.log(this);
        var oParent = this.parentNode;
        oList.removeChild(oParent);
      }
    }
  </script>
</body>
</html>